"use strict"
//开发者登录
const NAMETEST = /^[a-zA-Z0-9_-]{3,64}$/;

exports.format = {
    "id": 'develop',
    "name": "开发者",
    "fields": {
        "appid": { 'type': 'string', 'val': '', 'name': "随便填" },
    }
};

//登录与认证TOKEN
//user
//pass
exports.login = async function () {
    let user = this.get("user");
    if (!user) {
        return this.error("user empty");
    }
    let pass = this.get("pass");
    if (!pass) {
        return this.error("pass empty");
    }

    if (!NAMETEST.test(user)) {
        return this.error("user illegal", 'a-zA-Z0-9_-')
    }

    let developsModel = this.model.branch('develops');
    let ret = await developsModel.login(user);
    if (!ret) {
        return this.error('账号不存在');
    }
    if (ret['status'] < 1) {
        return this.error("账号已被禁用");
    }
    //BOBTODO 开发者密码做加密
    if (ret['xcode'] != pass) {
        return this.error('password error');
    }
    // let verify_xcode = developsModel.password(pass);
    // console.log(pass,verify_xcode,ret['xcode']);
    // if( verify_xcode !== ret['xcode']){
    //     return this.error('password error');
    // }
    return user;
}

exports.orderCreate = function (config) {
    let data = {};
    data["rmb"] = config['rmb'];
    data["attach"] = config['attach'];
    data["orderid"] = config['orderid'];
    return data;
}

/**
 * @name orderNotify
 * 验证平台发货信息
 */
exports.orderNotify = function () {
    let attach = this.get("attach", 'string');
    let orderid = this.get("orderid", 'string');
    return { "attach": attach, "orderid": orderid }
}

/**
 * @name orderResult
 * 包装游戏服发货信息
 */
exports.orderResult = function (err, ret) {
    return err ? err : ret;
}